<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <script>
        //数组解构
        let arr = [1, 2 ];
        // let [a, b, c, d, e] /*解构*/ = arr;
        // console.log(a);
        // console.log(b);
        // console.log(c);
        // console.log(d);

        let [a1, b1,c1='默认值'] = arr;
        console.log(a1, b1,c1);


        let { 0: first, [arr.length -1]: last } = arr;
        console.log(first);
        console.log(last);

        let s1 = [1, 2, 3];
        let s2 = [4, 5, 6];
        s1.push(...s2);
        console.log(s1);
     
        let x=[1,[2,3,4,5,6],7]
        const [a,[...zks],c]=x

        console.log(a,zks,c,'多重结构');




        //对象解构
        let person = {
            name: "zks",
            age: 20,
        };
        // let {
        //     name,
        //     age,
        // } = person;
        // console.log(name);

        let {
            name: newName, //赋值给新的名字
            age: newAge,
        } = person;
        console.log(newName, newAge);
        console.log("+" , name); //旧名字不能用

        //对象的简写
        const age = 10;
        const student = {
            name: "zks",
            age, //变量和属性名字一样可以写一个 相当于age:age
            // sayhello:function(){
            //     console.log(11);
            // }
            //函数的简写
            sayhello() {
                console.log(11);
            },
        };
        console.log(student);

        // 数组对象解构赋值
        const arrobj = [{ sname: 'sss2', id: 2 }];


        const [{ sname, id }] = arrobj
        console.log(sname, id);
    </script>
</body>

</html>